from flask_restful import reqparse,Resource,Api,marshal
from flask import jsonify,json,Blueprint

from models.user import VipModel
from common.models_fields import vip_fields

vip_bp = Blueprint('vip',__name__,url_prefix='/vip')
api = Api(vip_bp)
class VIPInfo(Resource):
    def get(self):
        """获取VIP信息"""
        vips = VipModel.query.all()
        result = {}
        for vip in vips:
            if vip.level == 0:
                # 是普通用户
                vips = marshal(vips, vip_fields)
                common_list = json.loads(json.dumps(vips))
                # common_list['level']='免费'
                result['common_list'] = common_list
            if vip.level == 1:
                common_vip_list = json.loads(json.dumps(marshal(vip, vip_fields)))
                common_vip_list['level'] = '普通会员'
                result['common_vip_list'] = common_vip_list
            if vip.level == 2:
                expert_vip_list = json.loads(json.dumps(marshal(vip, vip_fields)))
                expert_vip_list['level'] = '高级会员'
                result['expert_vip_list'] = expert_vip_list
        return jsonify(message='ok', data=result, code=200)
api.add_resource(VIPInfo,'/get_vip_list')
